<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-07-12 16:37
 *
 * Version: 2.0
 */

namespace App\Modules\Employee\Repositories;


use App\Models\UserStore;
use App\Modules\Employee\Criterias\getStoreInfoCriteria;
use App\Modules\Employee\Validators\UserStoreValidator;
use App\Modules\Store\Repositories\StoreRepository;
use Flower\Core\Repository\Eloquent\BaseRepository;

class UserStoreRepository extends BaseRepository
{
	public function model()
	{
		return UserStore::class;
	}

	public function validator()
	{
		return UserStoreValidator::class;
	}

	public function roles($userId,$storeId=null){
		$map = empty($storeId) ? ['uid'=>$userId] : [
			'uid' => $userId,
			'sid' => $storeId
		];
		return $res = $this->with('store')->findWhere($map);
	}


	/**
	 * 查询店铺是不是默认店铺
	 * @param $data
	 * @return mixed
	 */
	public function isDefault($data){
		return $this->model->where($data)->first();
	}


	/**
	 *  获取店铺信息
	 * @param $userId
	 * @param $storeId
	 * @return mixed
	 */
	public function getStoreByUserIdStoreId($userId,$storeId){
		$where = empty($storeId) ? ['uid'=>$userId] : ['uid'=>$userId,'sid'=>$storeId];
		return $this->with('store')->findWhere($where);
	}


	public function getUserInfoByRoleAndStoreId($role,$storeId){
		return $this->model->with('user:id,nick')->where(['rid'=>$role,'sid'=>$storeId])->get();
	}
}